package main

import (
	"common"
	"gateway/config"
	"gateway/core"
	"gateway/middware"
	"log"
)

func main() {
	// 初始化网关
	gw := core.New()

	// 注册中间件
	gw.Use(middware.Recovery())
	gw.Use(middware.RateLimiter(100))
	gw.Use(middware.Auth())

	// 加载路由配置
	if err := config.LoadFromFile("routes.json"); err != nil {
		log.Fatal(err)
	}
	config.ApplyRoutes(gw)

	// 启动服务
	log.Println("Gateway started on :8080")
	common.InitETCD("gateway", "127.0.0.1", 8080, "1")
	if err := gw.Run(":8080"); err != nil {
		log.Fatal(err)
	}
}
